const path = require('path');
const webpack = require('webpack');
module.exports = {
  publicPath: './',
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-pxtorem')({ // 把px单位换算成rem单位
            rootValue: 37.5, // 换算的基数(设计图750的根字体为32)
            propList: ['*']
          })
        ]
      }
    }
  },


  // baseUrl:'/jiangsu/testentrance/sjfhtest/web/',
  lintOnSave: true,
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@as', resolve('src/assets'))
      .set('@cp', resolve('src/components'))
      .set('@service', resolve('src/service'))
      .set('@static', resolve('src/static'))
      .set('@views', resolve('src/views'))
    const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
    types.forEach(type => addStyleResource(config.module.rule('scss').oneOf(type)))
  },
  configureWebpack: {
      performance: {
          hints:'warning',
          //入口起点的最大体积
          maxEntrypointSize: 50000000,
          //生成文件的最大体积
          maxAssetSize: 30000000,
          //只给出 js 文件的性能提示
          assetFilter: function(assetFilename) {
              return assetFilename.endsWith('.js');
          }
      },
        plugins: [
            new webpack.DllReferencePlugin({
                context: process.cwd(),
                manifest: require('./public/vendor/vendor-manifest.json')
            })
        ]
    },
  // webpack-dev-server 相关配置
  devServer: {
    host: '0.0.0.0',
    port: 8088,
    https: false,
    hotOnly: false,
    //   target: 'https://release.71ydj.com/',
    proxy: {
      '/api/': {
        target: 'https://bulid.71ydj.com',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/api/': ''
        }
      }
    },
    before: (app) => {
      console.log('​app', app)
    }
  }
}
// alias
function resolve(dir) {
  return path.join(__dirname, dir)
}
// 全局引入mixin
function addStyleResource(rule) {
  rule.use('style-resource')
    .loader('style-resources-loader')
    .options({
      patterns: [
        path.resolve(__dirname, './src/static/style/mix.scss'),
        path.resolve(__dirname, './src/static/style/global.scss'),
      ],
    })
}


